// VC10Dlg.h : header file
//

#if !defined(AFX_VC10DLG_H__277114C7_945D_11D6_82D2_0800460222F0__INCLUDED_)
#define AFX_VC10DLG_H__277114C7_945D_11D6_82D2_0800460222F0__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000




/////////////////////////////////////////////////////////////////////////////
// CVC10Dlg dialog

//#include "../RMSClient/VideoInformClient.h"
//#include "../RMSClient/SetFrameRateDlg.h"
#include "../RMSLib/channel.h"
//#include "../RMSLib/info.h"
//#include "../RMSClient/WaveOut.h"

#include "../RMSLib/AudioDecoder/CAudioDecoder.h"
#include "../RMSLib/AudioOut/CAudioOut.h"
#include "../Lib/BtnST.h"	// tansparent button & bitmaps

#include "../GUI/MegaDialog.h"
#include "../GUI/MegaDialogNvc.h"
#include "../GUI/MegaButton.h"
#include "../GUI/MegaSlider.h"
#include "../GUI/MegaBitmap.h"
#include "../GUI/MegaDrawer.h"
#include "MegaDrawerAddress.h"
#include "MegaDrawerOrganize.h"
#include "MegaDrawerVOD.h"

#include "../RMSLib/VC70SocketThread.h"
#include "../RMSLib/VC70ClientSession.h"
#include "TransparentStatic.h"
#ifdef VC70
	#include "../RMSLib/VideoPlayer.h"
#endif //VC70


#ifdef _NET_VC_
	#define IDD_THIS_DIALOG		IDD_NVC_DIALOG
	#define	VIEWER_MEGA_DIALOG	CMegaDialogNvc
#else //def _NET_VC_
	#define IDD_THIS_DIALOG		IDD_VC10_DIALOG 
	#define	VIEWER_MEGA_DIALOG	CMegaDialog
#endif //def _NET_VC_


#define	 ID_CLOSE_SESSION (WM_USER+333)


class MPoint : public CPoint
{
public:
	void SetPoint(int nx, int ny) { x = nx; y = ny; };
};


class CVC10Dlg : public VIEWER_MEGA_DIALOG, public ClientInterface, public CCallBack
{
//	friend class CVideoPlayer;

public:
	int		ObjectSize;
	map<CString, CSite> m_SitesLive;
	map<CString, CSite> m_SitesStored;

protected:	// external changes of addressbook prohibited!!!!!!!
	void initDirectX();
	void reinitDirectX(BOOL bGDI, BOOL bGDIfs, DWORD nSize);
	void reinitDirectX(BOOL* pbGDI, BOOL* pbGDIfs, DWORD nSize);
	void ReadAddressBook();
	void WriteAddressBook();
	void EnablePlaybackButtons(BOOL bEnable = TRUE);
	void UncheckPrevPBButton(CMegaButton * pNewBtn);
	void SetCaptureText(LPCTSTR txt);
	//unsigned int STREAM_BOX_MESSAGE;

void prepareFullScreenOutput();
void unprepareFullScreenOutput();
void redrawControls(DWORD sizeCode);

	CString m_strHomePath;
	void initHomePath();

private:

	WPARAM Call_IP;
	LPARAM Call_ID;

	CEvent RefreshVideo;

	int		m_nMinSizeX, m_nMinSizeY;
	BOOL	initdx;
	BOOL	dxfullscreen;

	CRect m_lastWinRect;
	DWORD m_dwStyle;

	CWnd*	m_FullScreenCWnd;
	int		needsUpdate;
	void	UpdateRegistry();
	void	RedrawGDI();
	void	getXY(int& x, int& y);
	void	getXY(int& x, int& y, DWORD dwSize);
	void	redrawScreenDX(int x, int y);
	void	DrawDXInfo(int x, int y);
	void	DrawDXVideo();
	void	ShowInfoBar();
	void	RedrawGDIFullScreen();
	BOOL	setSocketStatusToShow(BYTE status, DWORD ext);
  #ifdef _PACKET_LOSS_
	void	DrawPacketLossIndicator();
  #endif
  #ifdef _J707_PENDING_ //#103R210029
	void	DrawSpeakingFrame();
	bool b_speaking;
  #endif

	CMenu *m_pMenu;
	CMenu *m_pMenuPopup;
	BOOL InitializePopupMenu();

	CMegaBitmap m_VC10ViewerLogo, m_StreamboxLogo, m_StreamboxFullLogo;
	CMegaBitmap m_PartnerLogo;

	CMegaButton m_Size1Btn, m_Size2Btn, m_SizeFullBtn, m_VolBtn;
	CRgn m_rgBtn1, m_rgBtn2, m_rgBtnFull;

	CMegaButton m_Play, m_Stop, m_Wind, m_Rewind, m_Koma, m_KomaBack, m_Capture;

	CMegaButton * m_pPrevPBButton;

	CMegaSlider m_Volume;

	CRect m_rcChannel;
	int m_nInfoBarHeight;

	//New Dialog UI DoerIT2015/5/14 -> Sachith
	CMegaButton m_btnWinMinimize, m_btnWinClose, m_HideTopLine1, m_HideTopLine2, m_HideBottomLine; 
	MPoint m_ptWinMinimize, m_ptWinClose, m_ptHideTopLine1, m_ptHideTopLine2, m_ptHideBottomLine;

	// drawers
	CMegaDrawerAddress m_AddressDrawer;
	CMegaDrawerOrganize m_OrganizeDrawer;
	CTransparentStatic    m_MyStatic;
#ifdef VC70
	CMegaDrawerVOD m_VODDrawer;
#endif

	CString m_strAddressBookFileName;

	BYTE m_socketStatus;

	char m_szSocketStatus[100];
	char m_percentageString[100];
	BOOL m_bShowPercentage;

	LONG m_beginning;
	LONG m_ending;

	BOOL m_bMove, m_Dragable;
	CPoint m_moveCursorPos, m_moveOffset;

#ifdef _NET_VC_

	MPoint m_ptClose;
	MPoint m_ptSize;
	MPoint m_ptConnect;
	MPoint m_ptEncoderLogo;
	MPoint m_ptVolBtn;
	MPoint m_ptVolume;
	MPoint m_ptCapture;

	CMegaButton m_btnSize, m_btnClose, m_btnConnectDlg, m_btnSetting;  //Doerit 05-05-2015 -> Charith

	HANDLE m_hMutex;
	CString m_addr;
#endif //def _NET_VC_

	
	char* getReceivingPercentage(char* szTime, char* szDate);

#ifdef _PACKET_LOSS_
	MPoint m_ptCircle;
	bool   m_bPacketLoss;
	DWORD  m_dwPacketLossColor;
#endif //def _PACKET_LOSS_

// Construction
public:
	CVC10Dlg(CWnd* pParent = NULL);	// standard constructor
	virtual ~CVC10Dlg();

	void AdjustSize();

    string LeftBottomText;
    virtual int Execute(void* param); // for callback


	static LONG timeTagToLong(char* strTime, char* strDate);

	CString CurrentCam;

	// Dialog Data
	//{{AFX_DATA(CVC10Dlg)
	enum { IDD = IDD_THIS_DIALOG };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CVC10Dlg)
	public:
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	virtual BOOL OnInitDialog();
	virtual void OnDestroy();
	protected:
		virtual void DoDataExchange(CDataExchange* pDX);
	//}}AFX_VIRTUAL

// Implementation
protected:
	HICON m_hIcon;
#ifdef _J707_ // merge from VC-X by TOMOKOH to fix "#103R210002:KAZUHY"
    OSVERSIONINFO osVersionInfo;
#endif

	void UpdateVolumeBitmap();
	void capture();

	// Generated message map functions
	//{{AFX_MSG(CVC10Dlg)
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg UINT OnNcHitTest(CPoint point);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point); //New Dialog UI Dragable DoerIT2015/5/14 -> Sachith
	afx_msg void OnNcLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnNcRButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnMenuAudiosetting();
	afx_msg void OnMenuHomeFolder();
    afx_msg void OnMenuConnect();
	afx_msg void OnIDCClose();
	afx_msg void OnIDCMinimize();
	afx_msg void OnDirectXEnable();
	afx_msg void OnGDIFullScreen();
	afx_msg void OnMove();
	afx_msg void OnTop();
	afx_msg void OnSingleSize();
	afx_msg void OnDoubleSize();
	afx_msg void OnWideSize();
	afx_msg void OnFullSize();
	afx_msg void OnNewSize();
	afx_msg void OnConnect();
	afx_msg LRESULT OnConnectSite(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnConnectStoredSite(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnAddressBookChanged(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnSyncCameraSelection(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT User_Message(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnUpdateSessionStatus(WPARAM wParam, LPARAM lParam);
	afx_msg void OnPlayClick();
	afx_msg void OnStopClick();
	afx_msg void OnKomaClick();
	afx_msg void OnKomaBackClick();
	afx_msg void OnWindClick();
	afx_msg void OnRewindClick();
	afx_msg void OnCaptureClick();
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	#ifdef _PACKET_LOSS_
	afx_msg LRESULT OnRecivePacketLoss(WPARAM wParam, LPARAM lParam);
	#endif
	#ifdef _J707_PENDING_ //#103R210029
	afx_msg LRESULT OnSpeaking(WPARAM wParam, LPARAM lParam);
	#endif
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()

	BOOL OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	BOOL getTopMostFlagFromMenu(BOOL* pFlag);
	void switchTopMostFlag();

	BOOL DropPopupMenu(UINT nFlags, CPoint point);

public:

	CChannelInfo m_info;
	int timeOut;	// without update

	CRITICAL_SECTION m_criticalDecode;

	CVC70Session m_session;
	CChannel Channel;
//	CWaveOut m_WaveOut;
	BOOL m_bEnableRing;

	CAudioDecoder *m_decoder;
	CAudioOut *m_AudioOut;

	void UpdatePanel(BOOL bStatus, int nCamera);

	BOOL m_bStored;
#ifdef VC70
	BOOL m_bPlay;
	CVideoPlayer m_player;
	CMutex m_mutexFile;
#endif //def VC70

public:
	void enterCritical();
	void leaveCritical();

	CWaveSync* getSessionWaveSocket(int camera = 0);
	CVideoPlayer* getPlayer();
#ifdef _JNC_REC_
	void returnRecords(BYTE* p, DWORD dwLen);
#endif //def _JNC_REC_

	BYTE** getYComponent(int camera = 0);
	BYTE** getUComponent(int camera = 0);
	BYTE** getVComponent(int camera = 0);

	HWND getWindow();

	void setSessionTime(LPCTSTR time);
	void setSessionDate(LPCTSTR date);

	CSyncObject* getFileLock();
	LRESULT OnConnectFailed(WPARAM wParam, LPARAM lParam);

	map<CString, CSite>* getSitesLive();
	map<CString, CSite>* getSitesStored();

	CSite* getLiveSite(LPCTSTR site);
	CSite* getStoredSite(LPCTSTR site);

	CChannelInfo* getInfoLive(int channel = 0);
	CChannelInfo* getInfoStored(int channel = 0);

	int sessionConnect(int camera = 0);
	int sessionDisconnect(int camera = 0);

	LPCTSTR getHomePath();
	void saveHomePath(LPCTSTR path);
	LPCTSTR getAudioDriverName();
	void saveAudioDriverName(LPCTSTR name);

	void mesOut(LPCTSTR sFile, int sLine, LPCTSTR pFStr, va_list aList);
	void mesOut(LPCTSTR sFile, int sLine, LPCTSTR pFStr, ...);
	void warOut(LPCTSTR sFile, int sLine, LPCTSTR pFStr, va_list aList);
	void warOut(LPCTSTR sFile, int sLine, LPCTSTR pFStr, ...);
	void errOut(LPCTSTR sFile, int sLine, LPCTSTR pFStr, va_list aList);
	void errOut(LPCTSTR sFile, int sLine, LPCTSTR pFStr, ...);

	LPCTSTR getCallString(LPTSTR callStr, int maxlen);

	DWORD getFrameSize();

	BYTE* getDecoderMemory();
	CEvent* getRefreshEvent();
	BOOL getEnableRingFlag();


	void showControlsOnDisconnect() {};
	void setCameraInfo(int channel, CInfo& info) {};
	void SetAudioStatus(int iStatus) {};
	int getActiveChannel() { return 0; };
	void* getLivePage() { return NULL; };
	void* getStoredPage() { return NULL; };
	void messageOut(LPCTSTR msg, LPCTSTR title = NULL, LPARAM p1 = NULL, LPARAM p2 = NULL ) {};
	void warningOut(LPCTSTR msg, LPCTSTR title = NULL, LPARAM p1 = NULL, LPARAM p2 = NULL ) {};

#ifdef _TEC_
	BOOL isEncoderActive();
#endif //def _TEC_
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_VC10DLG_H__277114C7_945D_11D6_82D2_0800460222F0__INCLUDED_)
